import * as RongIMLib from '@rongcloud/imlib-next'

// 初始化融云 SDK
export function initRongCloud(appKey) {
    return RongIMLib.init({ appkey: appKey })
}

// 连接融云
export function connectRongCloud(token) {
    return RongIMLib.connect(token)
}

// 断开连接
export function disconnectRongCloud() {
    return RongIMLib.disconnect()
}

// 获取会话列表
export function getConversationList() {
    return RongIMLib.getConversationList()
}

// 发送文本消息
export function sendTextMessage(targetId, conversationType, content) {
    const conversation = {
        targetId,
        conversationType
    }
    const message = new RongIMLib.TextMessage({ content })
    return RongIMLib.sendMessage(conversation, message)
}

// 获取历史消息
export function getHistoryMessages(targetId, conversationType, options = {}) {
    const conversation = {
        targetId,
        conversationType
    }
    return RongIMLib.getHistoryMessages(conversation, options)
}

// 添加事件监听
export function addRongCloudListener(event, callback) {
    RongIMLib.addEventListener(event, callback)
}

// 移除事件监听
export function removeRongCloudListener(event, callback) {
    RongIMLib.removeEventListener(event, callback)
}

// 导出事件常量
export const RongCloudEvents = RongIMLib.Events
export const RongCloudConversationType = RongIMLib.ConversationType